﻿// BaseInstruction.cs
// THE ULTIMATE BASE INSTRUCTION CLASS

using System;


namespace armsim
{

    /// <summary>
    /// The Base class for all of the 32 bit ARM instructions
    /// </summary>
    public class BaseInstruction
    {

        /// <summary>
        /// A 32 bit arm encoded instruction 
        /// </summary> 
        public uint Instruction { get; protected set; }

        /// <summary>
        /// Specifies under what circumstances the code is to be executed.
        /// </summary>
        public uint ConditionFlags { get; protected set; }

        /// <summary>
        /// Specifies what kind of instruction this instruction is
        /// </summary>
        public uint Type { get; protected set; }

        /// <summary>
        /// Initializes a BaseInstruction instance with the ConditionFlags and Type properties set
        /// </summary>
        /// <param name="instruction">The 32 bit arm instruction to store and decode</param>
        public BaseInstruction(uint instruction)
        {
            this.Instruction = instruction;
            this.ConditionFlags = VirtualMemory.ExtractBits(instruction, 28, 31);
            this.Type = VirtualMemory.ExtractBits(instruction, 25, 27);
        }

        /// <summary>
        /// Executes the current instruction. To be overridden by child classes
        /// </summary>
        /// <param name="cpu">The VirtualCPU to execute in</param>
        public virtual void Execute(VirtualCPU cpu)
        {
            
        }

        /// <summary>
        /// Returns the assembly language that produced the arm instruction
        /// </summary>
        /// <param name="cpu">The VirtualCPU that may provide help to the method</param>
        /// <returns>an arm assembly instruction</returns>
        public virtual String ToAssembly(VirtualCPU cpu)
        {
            if (this.Instruction == 0)
            {

                return "NO OPERATION";
            }


            return this.ToString();
        }



    }
}
